#!/bin/bash

# 读取变量
source ./.env

echo "拉取镜像"
# docker pull kibana:$elasticsearch_version
docker load -i kibana-7.17.1.tar

echo "创建目录"
mkdir kibana kibana/conf

chmod -R 777 kibana

echo "创建配置文件"
touch kibana/conf/kibana.yml
cat << EOF > kibana/conf/kibana.yml
server.host: "0.0.0.0"
server.port: $kibana_inside_port
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://$node01_ip:$node01_outside_port", "http://$node02_ip:$node02_outside_port", "http://$node03_ip:$node03_outside_port" ]
monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: "zh-CN"
elasticsearch.requestTimeout: 300000
EOF

echo "创建启动脚本"
touch kibana/start.sh
cat << EOF > kibana/start.sh
#!/bin/bash
docker run \
    --name $kibana_name \
    -v $(pwd)/kibana/conf/kibana.yml:/usr/share/kibana/config/kibana.yml \
    -p $kibana_outside_port:$kibana_inside_port \
    -d docker.io/kibana:$elasticsearch_version
EOF

echo "启动容器"
sh kibana/start.sh